home *** CD-ROM | disk | FTP | other *** search
Text File | 1987-07-26 | 22.6 KB | 814 lines | [TEXT/MACA] |
- ;*
- ;*
- ;* Program Name: Turtle Assistant V1.0
- ;* Date Written: July 26, 1987
- ;* Author: Christopher J. Flynn
- ;* 2601 Claxton Drive
- ;* Herndon, VA 22071
- ;* Description:
- ;* Turtle Assistant introduces Logo newcomers to turtle graphics.
- ;* A control panel places common turtle commands within reach of a
- ;* button click. Other options are available via menus. Multiple
- ;* turtle drawing windows are suported.
- ;*
-
-
- ;
- ; G L O B A L V A R I A B L E S
- ;
- make "Black [255 255 255 255 255 255 255 255]
- make "White [0 0 0 0 0 0 0 0]
- make "Gray [170 85 170 85 170 85 170 85]
- make "LtGray [136 34 136 34 136 34 136 34]
- make "DkGray [119 221 119 221 119 221 119 221]
- make "Bricks [128 128 128 255 8 8 8 255]
- make "Weave [248 116 34 71 143 23 34 113]
- make "Marbles [119 137 143 143 119 152 248 248]
- make "Waffles [191 192 191 191 176 176 176 176]
-
-
-
- make "CurrentTurtleWindow []
- make "TurtleWindowID 0
-
- ;
- ; H O U S E K E E P I N G P R O C E D U R E S
- ;
-
- ;
- ; Procedure to clear/restore desktop when program is started/stopped
- ;
- to Go
- CleanUpToStart Windows
- InstallNewMenu
- make "ControlPanel (oneof :ControlWindow "ProcID 3)
- ask :ControlPanel [WSelect]
- end
-
- to CleanUpToStart :AllWindows
- if EmptyP :AllWindows [stop]
- LocalMake "W first :AllWindows
- ifelse or (MemberP :W Listeners) (MemberP :W FileWindows)
- _ [ask :W [HaveMake "HoldPos WPos SetWPos ScreenSize]]
- _ [ask :W [if ChangedP [SetWPos [5 40] WSelect] WClose]]
- CleanUpToStart butfirst :AllWindows
- end
-
- to CleanUpToQuit :AllWindows
- if EmptyP :AllWindows [stop]
- LocalMake "W first :AllWindows
- ifelse or (MemberP :W Listeners) (MemberP :W FileWindows)
- _ [ask :W [SetWPos :HoldPos EraseName "HoldPos]]
- _ [ask :W [WSelect WClose]]
- CleanUpToQuit butfirst :AllWindows
- end
-
-
- ;
- ; D E F I N E M E N U O B J E C T S
- ;
-
- ;
- ; Apple Menu
- ;
- make "HoldAppleMenu first Menus
- make "NewAppleMenu oneof Menu
- ask :NewAppleMenu [SetTitle ask :HoldAppleMenu [Title]]
- ask :NewAppleMenu [SetUpItems [
- _ |About TA|
- _ [Ignore (Dialog
- _ "|Turtle Assistant Version 1.0 - an Object Logo Program by Chris Flynn.|
- _ [OK])]]]
- make "AppleMenuItems butfirst ask :HoldAppleMenu [ItemList]
- while [not EmptyP :AppleMenuItems]
- _ [ask :NewAppleMenu [AddItem first :AppleMenuItems]
- _ make "AppleMenuItems butfirst :AppleMenuItems]
-
- ;
- ; File Menu
- ;
- make "FileMenu oneof Menu
- ask :FileMenu [SetTitle "File]
- ask :FileMenu [SetUpItems [
- _ |New/N| [MakeNewWindow]
- _ |Print/P| [DoPrint]
- _ |Quit/Q| [DoQuit]]]
-
- ;
- ; Edit Menu
- ;
- make "EditMenu oneof Menu
- ask :EditMenu [SetTitle "Edit]
- ask :EditMenu [SetUpItems [
- _ |Undo/Z| [ask ActionWindow [Undo]]
- _ |(-| []
- _ |Cut/X| [ask ActionWindow [Cut]]
- _ |Copy/C| [ask ActionWindow [Copy]]
- _ |Paste/V| [ask ActionWindow [Paste]]
- _ |Clear| [ask ActionWindow [Clear]]
- _ |Select All/A| [ask ActionWindow [SetSelection list 0 TextLength]]]
-
- ask :EditMenu [to Update]
- ifelse EqualP (ask first windows [:class]) "Desk.Accessory
- _ [Enable]
- _ [Disable]
- end
-
- ;
- ;-------- Recorder Menu
- ;
- make "RecorderMenu oneof Menu
- ask :RecorderMenu [SetTitle "Recorder]
-
- make "OnMenuItem kindof MenuItem
- ask :OnMenuItem [to Exist]
- Usual.Exist
- SetTitle "On
- SetAction [RecorderOn]
- end
-
- ask :OnMenuItem [to Update]
- if EmptyP :CurrentTurtleWindow [stop]
- ifelse ask :CurrentTurtleWindow [:RecordingP]
- _ [Check]
- _ [UnCheck]
- end
-
- make "OffMenuItem kindof MenuItem
- ask :OffMenuItem [to Exist]
- Usual.Exist
- SetTitle "Off
- SetAction [RecorderOff]
- end
-
- ask :OffMenuItem [to Update]
- if EmptyP :CurrentTurtleWindow [stop]
- ifelse ask :CurrentTurtleWindow [:RecordingP]
- _ [Uncheck]
- _ [Check]
- end
-
- make "EraseMenuItem kindof MenuItem
- ask :EraseMenuItem [to Exist]
- Usual.Exist
- SetTitle "Erase
- SetAction [RecorderErase]
- end
-
- ask :EraseMenuItem [to Update]
- end
-
- make "PlayBackMenuItem kindof MenuItem
- ask :PlayBackMenuItem [to Exist]
- Usual.Exist
- SetTitle "Playback
- setAction [RecorderPlayBack]
- end
-
- ask :PlayBackMenuItem [to Update]
- end
-
- ask :RecorderMenu [AddItem oneof :OnMenuItem]
- ask :RecorderMenu [AddItem oneof :OffMenuItem]
- ask :RecorderMenu [AddItem (oneof MenuItem "Title "|(-|)]
- ask :RecorderMenu [AddItem oneof :EraseMenuItem]
- ask :RecorderMenu [AddItem (oneof MenuItem "Title "|(-|)]
- ask :RecorderMenu [AddItem oneof :PlayBackMenuItem]
-
- to RecorderOn
- ask :CurrentTurtleWindow [HaveMake "RecordingP "True]
- end
-
- to RecorderOff
- ask :CurrentTurtleWindow [HaveMake "RecordingP "False]
- end
-
- to RecorderErase
- ask :CurrentTurtleWindow [HaveMake "DrawingHistory []]
- end
-
- to RecorderPlayBack
- LocalMake "AllCommands ask :CurrentTurtleWindow [:DrawingHistory]
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- if EmptyP :AllCommands [stop]
- LocalMake "Result GetNumber
- if or (EqualP first :Result "Cancel)
- _ (not NumberP last :Result)
- _ [stop]
- LocalMake "NTimes last :Result
- RunTheCommands :NTimes :ATurtle :AllCommands
- end
-
- to RunTheCommands :RepeatCount :TheTurtle :CommandList
- Define "TurtleCommands (list [] :CommandList)
- Repeat :RepeatCount [ask :TheTurtle [TurtleCommands]]
- end
-
-
- ;
- ;-------- Turtle Menu
- ;
- make "TurtleMenu oneof Menu
- ask :TurtleMenu [SetTitle "Turtle]
-
- make "ShowTurtleMenuItem kindof MenuItem
- ask :ShowTurtleMenuItem [to Exist]
- Usual.Exist
- if EqualP first :InitList "Turtle
- _ [SetTitle last :InitList]
- SetAction [SetTurtle]
- end
-
- make "HideTurtleMenuItem kindof MenuItem
- ask :HideTurtleMenuItem [to Exist]
- Usual.Exist
- if EqualP first :InitList "Turtle
- _ [SetTitle last :InitList]
- SetAction [SetTurtle]
- end
-
- ask :ShowTurtleMenuItem [to Update]
- if EmptyP :CurrentTurtleWindow [stop]
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- ifelse and (EqualP Title "Show)
- _ (ask :ATurtle [ShownP])
- _ [Check]
- _ [UnCheck]
- end
-
- ask :HideTurtleMenuItem [to Update]
- if EmptyP :CurrentTurtleWindow [stop]
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- ifelse and (EqualP Title "Hide)
- _ (not ask :ATurtle [ShownP])
- _ [Check]
- _ [UnCheck]
- end
-
- ask :TurtleMenu [AddItem (oneof :ShowTurtleMenuItem "Turtle "Show)]
- ask :TurtleMenu [AddItem (oneof :HideTurtleMenuItem "Turtle "Hide)]
-
- to SetTurtle
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- LocalMake "ShowOrHide ask ActionMenuItem [Title]
- ifelse Equalp :ShowOrHide "Show
- _ [ask :ATurtle [ShowTurtle]]
- _ [ask :ATurtle [HideTurtle]]
- ask :CurrentTurtleWindow [SaveIt word :ShowOrHide "Turtle]
- end
-
-
- ;
- ;-------- PenPattern Menu
- ;
- make "PatternMenu oneof Menu
- ask :PatternMenu [SetTitle "Pattern]
-
- make "PatternItem kindof MenuItem
- ask :PatternItem [to Exist]
- Usual.Exist
- SetTitle Item 2 :InitList
- HaveMake "PatternName Item 2 :InitList
- HaveMake "PatternValue Item 4 :InitList
- SetAction [SetThePattern]
- end
-
- ask :PatternItem [to Update]
- if EmptyP :CurrentTurtleWindow [stop]
- ifelse EqualP (ask :CurrentTurtleWindow [:MyPattern]) :PatternName
- _ [Check]
- _ [UnCheck]
- end
-
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "Black "Val :Black)]
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "White "Val :White)]
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "Gray "Val :Gray)]
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "LtGray "Val :LtGray)]
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "DkGray "Val :DkGray)]
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "Bricks "Val :Bricks)]
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "Weave "Val :Weave)]
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "Marbles "Val :Marbles)]
- ask :PatternMenu [AddItem (oneof :PatternItem "Name "Waffles "Val :Waffles)]
-
- to SetThePattern
- LocalMake "PatternPicked ask ActionMenuItem [:PatternName]
- Localmake "ValuePicked ask ActionMenuItem [:PatternValue]
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- ask :CurrentTurtleWindow [HaveMake "MyPattern :PatternPicked]
- ask :ATurtle [SetPenPattern :ValuePicked]
- ask :CurrentTurtleWindow [SaveIt "SetPenPattern]
- ask :CurrentTurtleWindow [SaveIt :ValuePicked]
- end
-
-
- ;
- ;-------- PenMode Menu
- ;
- make "PenModeMenu oneof Menu
- ask :PenModeMenu [SetTitle "Pen]
-
- make "PenModeItem kindof MenuItem
- ask :PenModeItem [to Exist]
- Usual.Exist
- if EqualP first :InitList "PenMode
- _ [SetTitle last :InitList]
- SetAction [SetThePenMode]
- end
-
- ask :PenModeItem [to Update]
- if EmptyP :CurrentTurtleWindow [stop]
- ifelse EqualP Title (ask :CurrentTurtleWindow [PenMode])
- _ [Check]
- _ [UnCheck]
- end
-
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "Up)]
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "Down)]
- ask :PenModeMenu [AddItem (oneof MenuItem "Title "|(-|)]
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "Erase)]
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "Paint)]
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "Reverse)]
- ask :PenModeMenu [AddItem (oneof MenuItem "Title "|(-|)]
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "DownNot)]
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "EraseNot)]
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "PaintNot)]
- ask :PenModeMenu [AddItem (oneof :PenModeItem "PenMode "ReverseNot)]
-
- to SetThePenMode
- LocalMake "ThePenMode ask ActionMenuItem [Title]
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- ask :ATurtle [SetPenMode :ThePenMode]
- ask :CurrentTurtleWindow [SaveIt "SetPenMode]
- ask :CurrentTurtleWindow [SaveIt :ThePenMode]
- end
-
-
- ;
- ;-------- PenSize Menu - Preset for some typical pensize configurations
- ;
- make "PenSizeMenu oneof Menu
- ask :PenSizeMenu [SetTitle "PenSize]
-
- make "PenSizeMenuItem kindof MenuItem
- ask :PenSizeMenuItem [to exist]
- Usual.Exist
- ifelse EqualP first :InitList "Size
- _ [HaveMake "MyPenSize last :InitList]
- _ [HaveMake "MyPenSize [1 1]]
- SetTitle (word first :MyPenSize "| by | last :MyPenSize)
- SetAction [SetThePenSize]
- end
-
- ask :PenSizeMenuItem [to Update]
- if EmptyP :CurrentTurtleWindow [stop]
- ifelse EqualP :MyPenSize ask :CurrentTurtleWindow [PenSize]
- _ [Check]
- _ [UnCheck]
- end
-
- make "WSizeMenuItem kindof MenuItem
- ask :WSizeMenuItem [to Exist]
- Usual.Exist
- SetTitle "|Pen Width|
- SetAction [SetThePenWidth]
- end
-
- ask :WSizeMenuItem [to Update]
- end
-
- make "HSizeMenuItem kindof MenuItem
- ask :HSizeMenuItem [to Exist]
- Usual.Exist
- SetTitle "|Pen Height|
- SetAction [SetThePenHeight]
- end
-
- ask :HSizeMenuItem [to Update]
- end
-
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [1 1])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [2 2])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [3 3])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [4 4])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [5 5])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [6 6])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [7 7])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [8 8])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [9 9])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [10 10])]
- ask :PenSizeMenu [AddItem (oneof :PenSizeMenuItem "Size [15 15])]
- ask :PenSizeMenu [AddItem (oneof MenuItem "Title "|(-|)]
- ask :PenSizeMenu [AddItem (oneof :WSizeMenuItem)]
- ask :PenSizeMenu [AddItem (oneof :HSizeMenuItem)]
-
-
- to SetThePenSize
- LocalMake "PenSizePicked ask ActionMenuItem [:MyPenSize]
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- ask :ATurtle
- _ [SetPenSize first :PenSizePicked last :PenSizePicked]
- ask :CurrentTurtleWindow [SaveIt "SetPenSize]
- ask :CurrentTurtleWindow [SaveIt first :PenSizePicked]
- ask :CurrentTurtleWindow [SaveIt last :PenSizePicked]
- end
-
- to SetThePenWidth
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- LocalMake "Width first ask :ATurtle [PenSize]
- LocalMake "Height last ask :ATurtle [PenSize]
- LocalMake "Msg
- _ "|Enter the pen width (a number between 0 and 127). |
- LocalMake "Result DialogWord :Msg :Width []
- if EqualP first :Result "Cancel [stop]
- if (or (not NumberP last :Result)
- _ (LessP last :Result 0)
- _ (GreaterP last :Result 127))
- _ [stop]
- ask :ATurtle [SetPenSize last :Result :Height]
- ask :CurrentTurtleWindow [SaveIt "SetPenSize]
- ask :CurrentTurtleWindow [SaveIt last :Result]
- ask :CurrentTurtleWindow [SaveIt :Height]
- end
-
- to SetThePenHeight
- LocalMake "ATurtle first ask :CurrentTurtleWindow [Turtles]
- LocalMake "Width first ask :ATurtle [PenSize]
- LocalMake "Height last ask :ATurtle [PenSize]
- LocalMake "Msg
- _ "|Enter the pen height (a number between 0 and 127). |
- LocalMake "Result DialogWord :Msg :Height []
- if EqualP first :Result "Cancel [stop]
- if (or (not NumberP last :Result)
- _ (LessP last :Result 0)
- _ (GreaterP last :Result 127))
- _ [stop]
- ask :ATurtle [SetPenSize :Width last :Result]
- ask :CurrentTurtleWindow [SaveIt "SetPenSize]
- ask :CurrentTurtleWindow [SaveIt :Width]
- ask :CurrentTurtleWindow [SaveIt last :Result]
- end
-
-
- ;
- ;-------- Windows Menu
- ;
- make "WindowMenu oneof Menu
- ask :WindowMenu [SetTitle "Windows]
-
- ask :WindowMenu [to Select :WhichOne]
- make "CurrentTurtleWindow (Item :WhichOne (DrawingWindows Windows []))
- ask :CurrentTurtleWindow [WSelect]
- SetDefaultTurtle ask :CurrentTurtleWindow [:TheTurtle]
- ask :ControlPanel [WSelect]
- end
-
- ask :WindowMenu [to Update]
- RemoveAllItems ItemList
- AddDrawingWindows DrawingWindows Windows []
- end
-
- to RemoveAllItems :TheItems
- if EmptyP :TheItems [stop]
- RemoveItem first :TheItems
- RemoveAllItems butfirst :TheItems
- end
-
- to AddDrawingWindows :WindowsToAdd
- if EmptyP :WindowsToAdd [stop]
- LocalMake "Temp oneof MenuItem
- ask :Temp [SetTitle ask first :WindowsToAdd [WTitle]]
- AddItem :Temp
- AddDrawingWindows butfirst :WindowsToAdd
- end
-
- to DrawingWindows :AllWindows :OnlyDrawing
- if EmptyP :AllWindows
- _ [output :OnlyDrawing]
- if (ask first :AllWindows [MyNameP "TheTurtle])
- _ [Make "OnlyDrawing sentence :OnlyDrawing first :AllWindows]
- DrawingWindows butfirst :AllWindows :OnlyDrawing
- end
-
-
-
- ;
- ; Install Menus
- ;
- to InstallNewMenu
- ClearMenuBar
- ask :NewAppleMenu [Install]
- ask :FileMenu [Install]
- ask :EditMenu [Install]
- ;ask :EditMenu [Disable] ;no edit menu for our game
- ask :RecorderMenu [Install]
- ask :TurtleMenu [Install]
- ask :PatternMenu [Install]
- ask :PenModeMenu [Install]
- ask :PenSizeMenu [Install]
- ask :WindowMenu [Install]
- end
-
-
-
- ;
- ; P R O C E D U R E S I N V O K E D F R O M M E N U
- ;
-
- to MakeNewWindow
- make "CurrentTurtleWindow (oneof :DrawingWindow "ProcID 4 "CloseP "False)
- make "TurtleWindowID :TurtleWindowID + 1
- ask :CurrentTurtleWindow [SetWTitle (word "|Turtle Window | :TurtleWindowID)]
- SetDefaultTurtle ask :CurrentTurtleWindow [:TheTurtle]
- ask :CurrentTurtleWindow [ShowTurtle]
- ask :ControlPanel [WSelect]
- end
-
- to DoPrint
- if EmptyP :CurrentTurtleWindow [stop]
- ask :CurrentTurtleWindow [HardCopy]
- end
-
- to DoQuit
- make "TurtleWindowID 0
- Make "CurrentTurtleWindow []
- CleanUpToQuit Windows
- SetMenuBar DefaultMenuBar
- TopLevel
- end
-
- to GetNumber
- LocalMake "Msg
- _ "|How many times to you wish to repeat the commands? |
- LocalMake "Result DialogWord :Msg 1 []
- Output :Result
- end
-
-
- ;
- ; C O N T R O L W I N D O W O B J E C T D E F I N I T I ON
- ;
-
- make "ControlWindow kindof TurtleWindow
-
- ask :ControlWindow [to exist]
- Usual.Exist
- SetWPos [3 30]
- SetWSize [90 300]
- SetWFont "Monaco
- SetWFontSize 9
- DrawControlBoxes
- HaveMake "CurrentCommand "|| ;the Command most recently selected
- HaveMake "CurrentDistance "|| ;the distance most recently entered
- HaveMake "CurrentAngle "|| ;the angle most recently entered
- HaveMake "CurrentParameter "Distance
- HaveMake "PointClicked []
- end
-
- ;
- ; Draw a box in the specified rectangle and place the text in the box.
- ; Output the rectangle.
- ;
- ask :ControlWindow [to MakeBox :Rect :Label]
- FrameRect :Rect
- MoveTo (Item 1 :Rect) + 4 (Item 2 :Rect) + 11
- Type :Label
- Output :Rect
- end
-
- ;
- ; Draw all ControlWindow boxes.
- ; Define ControlWindow object variables for each box.
- ;
- ask :ControlWindow [to DrawControlBoxes]
- HaveMake "MoveRect MakeBox [5 20 85 35] "|| ;Turtle movement
- InvertRect (InsetRect :MoveRect 1 1)
- HaveMake "FdRect MakeBox [5 40 85 55] "Forward
- HaveMake "BkRect MakeBox [5 55 85 70] "Back
- HaveMake "LtRect MakeBox [5 70 85 85] "Left
- HaveMake "RtRect MakeBox [5 85 85 100] "Right
- HaveMake "CSRect MakeBox [5 100 45 115] "CS
- HaveMake "HomeRect MakeBox [45 100 85 115] "Home
- MoveTo 7 141
- Type "|Dist.|
- MoveTo 49 141
- Type "|Angle|
- HaveMake "DistRect MakeBox [5 145 43 160] "|| ;Distance Entry
- HaveMake "AngleRect MakeBox [47 145 85 160] "|| ;Angle Entry
- InvertRect (InsetRect :DistRect 1 1)
- InvertRect (InsetRect :AngleRect 1 1)
- HaveMake "D0Rect MakeBox [5 165 45 180] "| 0 |
- HaveMake "D5Rect MakeBox [45 165 85 180] "| 5 |
- HaveMake "D1Rect MakeBox [5 180 45 195] "| 1 |
- HaveMake "D6Rect MakeBox [45 180 85 195] "| 6 |
- HaveMake "D2Rect MakeBox [5 195 45 210] "| 2 |
- HaveMake "D7Rect MakeBox [45 195 85 210] "| 7 |
- HaveMake "D3Rect MakeBox [5 210 45 225] "| 3 |
- HaveMake "D8Rect MakeBox [45 210 85 225] "| 8 |
- HaveMake "D4Rect MakeBox [5 225 45 240] "| 4 |
- HaveMake "D9Rect MakeBox [45 225 85 240] "| 9 |
- HaveMake "EraseRect MakeBox [5 240 85 255] "| Erase|
-
- HaveMake "RunRect MakeBox [5 275 85 290] "| ** RUN **|
-
- HaveMake "CmdRect [5 40 85 115] ;Enclose commands
- HaveMake "NumberRect [5 165 85 240] ;Enclose digits
- end
-
- ;
- ; Handle clicks in the Control Window
- ;
- ask :ControlWindow [to WClick :X :Y :Mods]
- HaveMake "PointClicked list :X :Y
- HandleClick :PointClicked
- Usual.WClick :X :Y :Mods
- end
-
- ask :ControlWindow [to HandleClick :ThePoint]
- if PtInRectP :ThePoint :CmdRect [DoCmd]
- if PtInRectP :ThePoint :NumberRect [DoNumber]
- if PtInRectP :ThePoint :EraseRect [DoErase]
- if PtInRectP :ThePoint :RunRect [DoRun]
- end
-
- ;
- ; Flash the box in which the mouse button was clicked.
- ; (Clicks are simple-minded. No check is made to see if the mouse
- ; button is released in the same button as the click.)
- ;
- ask :ControlWindow [to FlashRect :Rect]
- InvertRect (InsetRect :Rect 1 1)
- wait .25
- InvertRect (InsetRect :Rect 1 1)
- end
-
- ;
- ; Process turtle movement commands. Store the selected command an
- ; object variable.
- ;
- ask :ControlWindow [to DoCmd]
- if PtInRectP :PointClicked :FdRect
- _ [SetCommand :FdRect "Forward
- _ HaveMake "CurrentParameter "Distance]
- if PtInRectP :PointClicked :BkRect
- _ [SetCommand :BkRect "Back
- _ HaveMake "CurrentParameter "Distance]
- if PtInRectP :PointClicked :LtRect
- _ [SetCommand :LtRect "Left
- _ HaveMake "CurrentParameter "Angle]
- if PtInRectP :PointClicked :RtRect
- _ [SetCommand :RtRect "Right
- _ HaveMake "CurrentParameter "Angle]
- if PtInRectP :PointClicked :CSRect
- _ [SetCommand :CSRect "ClearScreen]
- if PtInRectP :PointClicked :HomeRect
- _ [SetCommand :HomeRect "Home]
- end
-
- ask :ControlWindow [to SetCommand :Rect :Command]
- FlashRect :Rect
- HaveMake "CurrentCommand :Command
- DisplayCommand :Command
- end
-
- ;
- ; Display the selected command.
- ;
- ask :ControlWindow [to DisplayCommand :Command]
- EraseRect (InsetRect :MoveRect 1 1)
- MoveTo (Item 1 :MoveRect) + 4 (Item 2 :MoveRect) + 11
- Type :Command
- InvertRect (InsetRect :MoveRect 1 1)
- end
-
- ;
- ; Process digit clicks. Assemble the digits into a result field.
- ;
- ask :ControlWindow [to DoNumber]
- if PtInRectP :PointClicked :D0Rect [DoDigit :D0Rect 0]
- if PtInRectP :PointClicked :D1Rect [DoDigit :D1Rect 1]
- if PtInRectP :PointClicked :D2Rect [DoDigit :D2Rect 2]
- if PtInRectP :PointClicked :D3Rect [DoDigit :D3Rect 3]
- if PtInRectP :PointClicked :D4Rect [DoDigit :D4Rect 4]
- if PtInRectP :PointClicked :D5Rect [DoDigit :D5Rect 5]
- if PtInRectP :PointClicked :D6Rect [DoDigit :D6Rect 6]
- if PtInRectP :PointClicked :D7Rect [DoDigit :D7Rect 7]
- if PtInRectP :PointClicked :D8Rect [DoDigit :D8Rect 8]
- if PtInRectP :PointClicked :D9Rect [DoDigit :D9Rect 9]
- end
-
- ask :ControlWindow [to DoDigit :Rect :Digit]
- FlashRect :Rect
- if EqualP :CurrentParameter "Distance
- _ [HaveMake "CurrentDistance word :CurrentDistance :Digit
- _ if GreaterP (count :CurrentDistance) 3
- _ [HaveMake "CurrentDistance butfirst :CurrentDistance]
- _ DisplayNumber :CurrentDistance :DistRect]
- if EqualP :CurrentParameter "Angle
- _ [HaveMake "CurrentAngle word :CurrentAngle :Digit
- _ if GreaterP (count :CurrentAngle) 3
- _ [HaveMake "CurrentAngle butfirst :CurrentAngle]
- _ DisplayNumber :CurrentAngle :AngleRect]
- end
-
- ask :ControlWindow [to DisplayNumber :Number :Rect]
- EraseRect (InsetRect :Rect 1 1)
- MoveTo (Item 1 :Rect) + 4 (Item 2 :Rect) + 11
- (Type :Number)
- InvertRect (InsetRect :Rect 1 1)
- end
-
- ;
- ; Erase the integer entered so far.
- ;
- ask :ControlWindow [to DoErase]
- FlashRect :EraseRect
- if Equalp :CurrentParameter "Distance
- _ [make "CurrentDistance "||
- _ DisplayNumber :CurrentDistance :DistRect]
- if Equalp :CurrentParameter "Angle
- _ [make "CurrentAngle "||
- _ DisplayNumber :CurrentAngle :AngleRect]
-
- end
-
- ;
- ; Run the currently entered procedure.
- ; The gobal variable CurrentTurtleWindow contains the most recently
- ; created turtle window.
- ;
- ask :ControlWindow [to DoRun]
- LocalMake "Cmd :CurrentCommand
- LocalMake "Dist :CurrentDistance
- LocalMake "Angle :CurrentAngle
- if or (EmptyP :CurrentTurtleWindow)
- _ (EmptyP :Cmd)
- _ [stop]
- FlashRect :RunRect
- if EqualP :Cmd "ClearScreen [RunCS]
- if EqualP :Cmd "Home [RunHome]
- if EqualP :Cmd "Forward [RunFd :Dist]
- if Equalp :Cmd "Back [RunBk :Dist]
- if EqualP :Cmd "Left [RunLt :Angle]
- if EqualP :Cmd "Right [RunRt :Angle]
- end
-
- ask :ControlWindow [to RunCS]
- ask :CurrentTurtleWindow [ClearScreen]
- ask :CurrentTurtleWindow [SaveIt "ClearScreen]
- end
-
- ask :ControlWindow [to RunHome]
- ask :CurrentTurtleWindow [Home]
- ask :CurrentTurtleWindow [SaveIt "Home]
- end
-
- ask :ControlWindow [to RunFd :Dist]
- ask :CurrentTurtleWindow [Fd :Dist]
- ask :CurrentTurtleWindow [SaveIt "Fd]
- ask :CurrentTurtleWindow [SaveIt :Dist]
- end
-
- ask :ControlWindow [to RunBk :Dist]
- ask :CurrentTurtleWindow [Bk :Dist]
- ask :CurrentTurtleWindow [SaveIt "Bk]
- ask :CurrentTurtleWindow [SaveIt :Dist]
- end
-
- ask :ControlWindow [to RunRt :Angle]
- ask :CurrentTurtleWindow [Rt :Angle]
- ask :CurrentTurtleWindow [SaveIt "Rt]
- ask :CurrentTurtleWindow [SaveIt :Angle]
- end
-
- ask :ControlWindow [to RunLt :Angle]
- ask :CurrentTurtleWindow [Lt :Angle]
- ask :CurrentTurtleWindow [SaveIt "Lt]
- ask :CurrentTurtleWindow [SaveIt :Angle]
- end
-
-
- ;
- ; D R A W I N G W I N D O W O B J E C T D E F I N I T I O N
- ;
-
- make "DrawingWindow kindof TurtleWindow
-
- ask :DrawingWindow [to exist]
- Usual.Exist
- SetWpos [98 40]
- SetWSize [410 295]
- HaveMake "TheTurtle OneOf Turtle
- HaveMake "MyPattern "Black
- HaveMake "DrawingHistory [] ;Record of turtle commands
- HaveMake "RecordingP "False ;Initially not recording
- end
-
- ask :DrawingWindow [to SaveIt :CommandWord]
- if not :RecordingP [stop]
- HaveMake "DrawingHistory lput :CommandWord :DrawingHistory
- end
-
- ;
- ; Let's start!
-
- GO